package com.wang.todoList.controller;


import com.wang.todoList.VO.PasswordVo;
import com.wang.todoList.constant.BaseConstant;
import com.wang.todoList.entity.Admin;
import com.wang.todoList.service.AdminService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author zifan
 * @since 2021-07-10
 */
@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;

    @ApiOperation("用户注册")
    @PostMapping("/register")
    public Map<String,Object> register(@RequestBody Admin admin){
        return adminService.register(admin);
    }

    @ApiOperation("用户登录")
    @PostMapping("/login")
    public Map<String,Object> login(@RequestBody Admin admin){
        return adminService.login(admin);
    }

    @ApiOperation("测试token是否过期")
    @GetMapping("/test")
    public String testAuth(){
        return BaseConstant.REQUEST_SUCCESS;
    }

    @ApiOperation("获取用户信息")
    @GetMapping("/getAdminInfo")
    public Map<String,Object> getAdminInfo(HttpServletRequest request){
        return adminService.getAdminInfo(request);
    }

    @ApiOperation("修改用户信息")
    @PostMapping("/modifyAdminInfo")
    public Map<String,Object> modifyAdminInfo(HttpServletRequest request,@RequestBody Admin admin){
        return adminService.modifyAdminInfo(request,admin);
    }

    @ApiOperation("校验密码是否正确")
    @PostMapping("/checkPassword")
    public Map<String,Object> checkPassword(HttpServletRequest request, @RequestBody PasswordVo passwordVo){
        return adminService.checkPassword(request,passwordVo);
    }

    @ApiOperation("生成验证码")
    @GetMapping(value = "/captcha",produces = "image/jpeg")
    public void captcha(HttpServletRequest request, HttpServletResponse response){
        adminService.captcha(request,response);
    }

    @ApiOperation("修改密码")
    @PostMapping("/updatePassword")
    public Map<String,Object> updatePassword(HttpServletRequest request,@RequestBody PasswordVo passwordVo){
        return adminService.updatePassword(request, passwordVo);
    }


}

